package com.yulongtian.offers.day202209.day20220905;

/**
 * https://leetcode.cn/problems/er-wei-shu-zu-zhong-de-cha-zhao-lcof/submissions/
 * @author YulongTian
 * @date 2022/9/5 - 13:04
 */
public class Test01 {
    public static void main(String[] args) {

    }

    public static boolean findNumberIn2DArray(int[][] matrix, int target) {
        int m = matrix.length;
        if(m==0){
            return false;
        }
        int n = matrix[0].length;
        if(n==0){
            return false;
        }
        int i=0;
        int j=n-1;
        while (true){
            if(target==matrix[i][j]){
                return true;
            }
            if(target<matrix[i][j]){
                if(j-1<0){
                    return false;
                }else{
                    j--;
                    continue;
                }
            }
            if(target>matrix[i][j]){
                if(i+1>=m){
                    return false;
                }else{
                    i++;
                    continue;
                }
            }
            break;
        }


        return false;
    }

}
